<?php
class Default_Model_Message extends Zend_Db_Table{

	protected $_name = MESSAGE_TABLE;
	protected $_primary = 'message_id';

	private $MESSAGE_ID = 'message_id';
	private $TO_UID = 'receiver';
	private $FROM_UID = 'sender';

	protected $db;

	public function __construct(){
		//Goi ket noi voi Zend Db
		$this->db = Zend_Registry::get('connectDB');
	}

	protected $_messageError = null;
	
	// Xoa mess
	public function deleteMessageByUserId($userId){
		try {
			$this->db->delete(MESSAGE_TABLE,$this->TO_UID.' = ' . $userId . ' OR '. $this->FROM_UID.' = ' . $userId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}

	public function getError(){
		return $this->_messageError;
	}
}